﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class contacus : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnEnviar_Click(object sender, EventArgs e)
    {
        SendMessage();
    }
    protected void btnBorrar_Click(object sender, EventArgs e)
    {
        txtNombre.Text = "";
        txtEmail.Text = "";
        txtEmpresa.Text = "";
        txtMensaje.Text = "";
        txtTelefono.Text = "";
    }

    private void SendMessage()
    {
        String nom = this.txtNombre.Text;
        String mail = this.txtEmail.Text;
        String des = this.txtMensaje.Text;
        if ((nom != "") && (mail.Contains("@") && mail.Contains(".")) && (des != ""))
        {
            System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();
            correo.From = new System.Net.Mail.MailAddress(this.txtEmail.Text);
            correo.To.Add("info@ddevcom.com");
            correo.Body = "Empresa: " + this.txtEmpresa.Text + ", Telefono: " + this.txtTelefono.Text + ", Nombre: " + this.txtNombre.Text + ", Mensaje: " + this.txtMensaje.Text;
            correo.IsBodyHtml = false;
            correo.Priority = System.Net.Mail.MailPriority.Normal;
            System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
            smtp.Host = "mail.ddevcom.com";
            //smtp.Port = 25;
            //
            //---------------------------------------------
            // Estos datos debes rellanarlos correctamente
            //---------------------------------------------
            //smtp.Host = "servidor de correo";
            smtp.Credentials = new System.Net.NetworkCredential("info@ddevcom.com", "abc123ABC");
            //smtp.EnableSsl = false;
            try
            {
                smtp.Send(correo);
                lblError.Text = "Mensaje enviado satisfactoriamente";
            }
            catch (Exception)
            {
                lblError.Text = "Ingrese nuevamente los datos.";
            }
        }
        else
        {
            lblError.Text = "Ingrese nuevamente los datos.";
        }
    }
}
